<?php

namespace App\Admin\Controllers;

use Encore\Admin\Form;
use Encore\Admin\Http\Controllers\AdminController;
use App\Models\CategoryModel;
use Encore\Admin\Tree;
use Encore\Admin\Layout\Content;

class CategoryController extends AdminController
{

    public function index(Content $content)
    {
        $tree = new Tree(new CategoryModel);

        return $content
            ->header('栏目')
            ->body($tree);
    }


    protected function form()
    {
        $form = new Form(new CategoryModel());
        $form->text('name', '栏目名称')->rules('required');
        $form->select('parent_id', '所属类别')->options(CategoryModel::selectOptions());
        return $form;
    }
}
